package com.xiaohua.system.controller;

import com.xiaohua.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaohua.common.annotation.Log;
import com.xiaohua.common.core.controller.BaseController;
import com.xiaohua.common.core.domain.AjaxResult;
import com.xiaohua.common.enums.BusinessType;
import com.xiaohua.system.domain.XhFiles;
import com.xiaohua.system.service.IXhFilesService;
import com.xiaohua.common.utils.poi.ExcelUtil;
import com.xiaohua.common.core.page.TableDataInfo;

/**
 * 文件管理Controller
 *
 * @author 小花
 * @date 2025-04-05
 */
@RestController
@RequestMapping("/system/files")
public class XhFilesController extends BaseController {
    @Autowired
    private IXhFilesService xhFilesService;

    /**
     * 查询文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:files:list')")
    @GetMapping("/list")
    public TableDataInfo list(XhFiles xhFiles) {
        startPage();
        List<XhFiles> list = xhFilesService.selectXhFilesList(xhFiles);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:files:export')")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XhFiles xhFiles) {
        List<XhFiles> list = xhFilesService.selectXhFilesList(xhFiles);
        ExcelUtil<XhFiles> util = new ExcelUtil<XhFiles>(XhFiles.class);
        util.exportExcel(response, list, "文件管理数据");
    }

    /**
     * 获取文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:files:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId) {
        return success(xhFilesService.selectXhFilesByFileId(fileId));
    }

    /**
     * 新增文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:files:add')")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XhFiles xhFiles) {
        return toAjax(xhFilesService.insertXhFiles(xhFiles));
    }

    /**
     * 修改文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:files:edit')")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XhFiles xhFiles) {
        return toAjax(xhFilesService.updateXhFiles(xhFiles));
    }

    /**
     * 删除文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:files:remove')")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds) {
        return toAjax(xhFilesService.deleteXhFilesByFileIds(fileIds));
    }
}